package com.eclink.asset.controller;

import com.eclink.asset.convert.AssetItemConvert;
import com.eclink.asset.domain.dao.PrintTagModel;
import com.eclink.asset.service.PrintTagModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags ="标签打印模板管理")
@RestController
@RequestMapping("printTagModel")
public class PrintTagModelController {

    @Resource
    private PrintTagModelService service;

    @Resource
    private AssetItemConvert convert;

    @ApiOperation("查询")
    @PostMapping("/list/{labelType}")
    public ResponseEntity<List<PrintTagModel>> list(@PathVariable Integer labelType) {
        List<PrintTagModel> list = service.selectList(labelType);
        return ResponseEntity.ok(list);
    }

    @ApiOperation("新增")
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody PrintTagModel entity) {
        return ResponseEntity.ok(service.insert(entity));
    }

    @ApiOperation("修改")
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody PrintTagModel entity) {
        return ResponseEntity.ok(service.update(entity));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseEntity<Integer> remove(@PathVariable Long id) {
        service.deleteById(id);
        return ResponseEntity.ok(1);
    }

    @ApiOperation("选择")
    @PostMapping("/select/{id}")
    public ResponseEntity<Integer> select(@PathVariable Long id) {
        service.setSelected(id);
        return ResponseEntity.ok(1);
    }

    @ApiOperation("获取选择")
    @GetMapping("/getSelect")
    public ResponseEntity<PrintTagModel> getSelect() {
        return ResponseEntity.ok(service.getSelected());
    }

}
